package com.ruoyi.quartz.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.quartz.domain.StockTransactionDaily;
import com.ruoyi.quartz.service.IStockTransactionDailyService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 股票每日交易Controller
 * 
 * @author ruoyi
 * @date 2023-11-24
 */
@Controller
@RequestMapping("/finance/daily")
public class StockTransactionDailyController extends BaseController
{
    private String prefix = "finance/daily";

    @Autowired
    private IStockTransactionDailyService stockTransactionDailyService;

    @RequiresPermissions("finance:daily:view")
    @GetMapping()
    public String daily()
    {
        return prefix + "/daily";
    }

    /**
     * 查询股票每日交易列表
     */
    @RequiresPermissions("finance:daily:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StockTransactionDaily stockTransactionDaily)
    {
        startPage();
        List<StockTransactionDaily> list = stockTransactionDailyService.selectStockTransactionDailyList(stockTransactionDaily);
        return getDataTable(list);
    }

    /**
     * 导出股票每日交易列表
     */
    @RequiresPermissions("finance:daily:export")
    @Log(title = "股票每日交易", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StockTransactionDaily stockTransactionDaily)
    {
        List<StockTransactionDaily> list = stockTransactionDailyService.selectStockTransactionDailyList(stockTransactionDaily);
        ExcelUtil<StockTransactionDaily> util = new ExcelUtil<StockTransactionDaily>(StockTransactionDaily.class);
        return util.exportExcel(list, "股票每日交易数据");
    }

    /**
     * 新增股票每日交易
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存股票每日交易
     */
    @RequiresPermissions("finance:daily:add")
    @Log(title = "股票每日交易", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(StockTransactionDaily stockTransactionDaily)
    {
        return toAjax(stockTransactionDailyService.insertStockTransactionDaily(stockTransactionDaily));
    }

    /**
     * 修改股票每日交易
     */
    @RequiresPermissions("finance:daily:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        StockTransactionDaily stockTransactionDaily = stockTransactionDailyService.selectStockTransactionDailyById(id);
        mmap.put("stockTransactionDaily", stockTransactionDaily);
        return prefix + "/edit";
    }

    /**
     * 修改保存股票每日交易
     */
    @RequiresPermissions("finance:daily:edit")
    @Log(title = "股票每日交易", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(StockTransactionDaily stockTransactionDaily)
    {
        return toAjax(stockTransactionDailyService.updateStockTransactionDaily(stockTransactionDaily));
    }

    /**
     * 删除股票每日交易
     */
    @RequiresPermissions("finance:daily:remove")
    @Log(title = "股票每日交易", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(stockTransactionDailyService.deleteStockTransactionDailyByIds(ids));
    }
}
